<%@page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>项目信息</title>
<%@ include file="../../common/common.jsp"%>
 
<style type="text/css">

.fitem {
	margin-bottom: 3px;
}

.fitem label {
	display: inline-block;
	margin-bottom：2px;
	width: 60px;
}


</style> 
 
 
<script type="text/javascript">


function pro_statusFormatter(value,row,index){
	if (value==0){
		var s = '未编制';
		return s;
	}
	if (value==1){
		var s = '已编制';
		return s;
	}
	if (value==2){
		var s = '已审核';
		return s;
	}
}


//初始化项目信息
$(function(){
	$('#dg').datagrid({
		view: detailview,
		detailFormatter:function(index,row){
			return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>';
		},
		onExpandRow: function(index,row){
			
			$('#ddv-'+index).datagrid({
				url:'<%=basePath%>loadProWorkDetailAction.do?projectWorkInfo.projectinfo_id='+row.id,
				fitColumns:true,
				singleSelect:true,
				height:'auto',
				width:'600',
				columns:[[
					{field:'cesspoolNo',title:'化粪池编号',width:20},
					{field:'cesspoolDoPerson',title:'施工分队',width:20},
					{field:'cesspoolType',title:'类型',width:20},
					{field:'cesspoolDoContent',title:'工程内容',width:40},									
					{field:'cesspoolBudgetPrice',title:'预算价',width:30}
					
				]],
				onResize:function(){
					$('#dg').datagrid('fixDetailRowHeight',index);
				},
				onLoadSuccess:function(){
					setTimeout(function(){
						$('#dg').datagrid('fixDetailRowHeight',index);
					},0);
				}
			});
			$('#dg').datagrid('fixDetailRowHeight',index);
		}
	});
});
	
		
		

//新增项目
function newPro_info() {
	
	jQuery('#company_code').combobox({
	    url:'<%=basePath%>jsp/GetJson.jsp?type=companyinfoList',
	    valueField:'companyCode',
	    textField:'companyName'
	});
	
	$('#dlg').dialog('open').dialog('setTitle', '新增项目');
	$('#fm').form('clear');		
	$('#tt_tab').tabs('close','工程信息');
}

//工程信息tab
function _add_tab(title){
	var url = "tab_projectWorkinfo.jsp";
	 if ($('#tt_tab').tabs('exists', title)){ 
		 $('#tt_tab').tabs('select', title);    
	}else{
		$('#tt_tab').tabs('add',{
			 title:title, 
			 content:'<iframe scrolling="no" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>', 
			 closable:true 		 
		 })	
	}	
}

//编辑工程
function editPro_info() {
	jQuery('#company_code').combobox({
	    url:'<%=basePath%>jsp/GetJson.jsp?type=companyinfoList',
	    valueField:'companyCode',
	    textField:'companyName'
	});
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$('#dlg').dialog('open').dialog('setTitle', '编辑项目');	
		//项目id projectInfo.id
		$('#projectinfo_id').attr('value',row.id);
		//工程信息tab
		_add_tab("工程信息");
		$('#fm').form('load', row);
		
	}
}


// 初始化合同 grid
$(function(){
	
	$('#cc').combogrid({
		panelWidth:450,
		idField:'id',
		textField:'contractName',
		url:'<%=basePath %>contractInfoAction!loadData.do',
		columns:[[
			{field:'contractNo',title:'合同编号',width:80},
			{field:'contractName',title:'合同名称',width:100},
			{field:'createTime',title:'创建时间',width:100},
			{field:'budgetPrice',title:'预算价格',width:100},
			{field:'contractPrice',title:'合同价格',width:100}
		]],
		pagination:"true" 
	}) 	
	
})



 //删除项目信息
function removePro_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$.messager.confirm('Confirm',
				'您确认删除此记录?', function(r) {
					if (r) {
						$.post('<%=basePath %>saveProjectInfoAction!destroy.do', {
							id : row.id
						}, function(result) {
							$('#dg').datagrid('reload');
						}, 'json');
					}
				});
	}
}


function project_save(){
	 var checkText=$("#cc").combogrid('getText');
	 if(checkText!=''){
		 $("#cc_field").attr('value',checkText);
	 }
	$('#fm').form('submit',{
		url:'<%=basePath %>saveProjectInfoAction.do',
		onSubmit: function() {
			return $(this).form('validate');
		},
		success:function(result){
		var result = eval('(' + result + ')');
			 if (result.message=='1') {	
				 //把新增的项目id 返回
			    $('#projectinfo_id').attr('value',result.id);
				// auto select tab -工程信息
				$.messager.confirm('提示','保存成功，是否继续添加工程信息',function(r){  
				      if (r){  
				    		_add_tab("工程信息");
				      }  
				 }); 
			
			}
			else if(result.message=='2'){
				 $.messager.alert('提示',"保存成功");
			}
			else {
				$.messager.show( {
					title : '错误提示',
					msg : "保存失败"
				});
			} 
		}
	})
		 
}
		

<%-- // tabs tools save 
function tab_save(){
	
	var p = $('#tt_tab').tabs('getSelected');
	var title = p.panel('options').title;
	
	//保存工程信息
	if(title=='项目信息'){
		// set contractinfo_name to field
		 var checkText=$("#cc").combogrid('getText');
		 if(checkText!=''){
			 $("#cc_field").attr('value',checkText);
		 }
		 	 		
	 	$('#fm').form('submit',{
			url:'<%=basePath %>saveProjectInfoAction.do',
			onSubmit: function() {
				return $(this).form('validate');
			},
			success:function(result){
			alert(result);
			var result = eval('(' + result + ')');
			 if (result.message=='1') {	
				 //把新增的项目id 返回
			    $('#projectinfo_id').attr('value',result.id);
				// auto select tab -工程信息
				$.messager.confirm('提示','保存成功，是否继续添加工程信息',function(r){  
				      if (r){  
				    		_add_tab("工程信息");
				      }  
				 }); 
			
			}
			 else if(result.message=='2'){
				 $.messager.alert('提示',"保存成功");
			 }
			else {
				$.messager.show( {
					title : '错误提示',
					msg : "保存失败"
				});
			} 
		}
			
			
		}) 
		
	}
	if(title=='工程信息'){
		$.messager.confirm('提示','请确认是否已经保存了添加的工程信息',function(r){  
		      if (r){  
		    	  $('#dlg').dialog('close'); // close the dialog
		  			window.location.reload(); // reload the user data
		      }  
		 }); 
		
		
	}
	
} --%>



function _fun_close(){
	$('#dlg').dialog('close');
}
		
		
	</script>
</head>
<body>

	<div id="toolbar">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" 
				onclick="newPro_info()">新建</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit"
				 onclick="editPro_info()">编辑</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove"
				 onclick="removePro_info()">删除</a>
	</div>
	
	<table id="dg" style="width:1130px;height:370px"
			url="<%=basePath %>loadProjectInfoAction.do" 
			title="项目信息"
			singleSelect="true" fitColumns="true" pagination = "true" toolbar="#toolbar" >
		<thead>
			<tr>
				<th field="contractinfo_name" width="40" align="center" >所属合同名称</th>
				<th field="projectName" align="center" width="40">项目名称</th>
				<th field="constructionOrganization" align="center" width="18">施工单位</th>
				<th field="constructionAddr" align="center" width="18">施工地点</th>
				<th field="pipeLength" width="18" >管道长度</th>
				<th field="managerCompanyInfo" width="20" align="center">物管信息</th>
				<th field="residentCount" width="15" align="center">总户数</th>
				<th field="buildArea" width="15" align="center">总面积</th>
				<th field="pitCount" width="18" align="center">化粪池数</th>
				<th field="budgetPrice" width="22" align="center">项目预算价</th>
				<th field="contractPrice" width="22" align="center">项目合同价</th>
				<th field="createTime" width="18" align="center">创建时间</th>
				<th field=projectStatus width="15" align="center" formatter="pro_statusFormatter" >状态</th>
				<th field="projectSpec" width="30" align="center">项目说明</th>
			</tr>
		</thead>
	</table>
	
	<div id="dlg" class="easyui-dialog"
			style="width: 800px; height: 370px; padding: 1px 2px" closed="true" 
			buttons="#dlg-buttons">
	<!-- 工程id -->
    <input id="projectinfo_id" type="hidden">		
			
	<div id="tt_tab" class="easyui-tabs"  style="width:780px;height:280px;" tools="#tab-tools"">
	<!-- tabs -->	
		<div title="项目信息" tools="#p-tools" style="padding:1px;">
		
			<form id="fm" method="post">
				
			<!-- 合同区域 -->
			<div>
				<table style="border:1px solid #b3dfda;width: 700px">
					<tr>
						<td>
							<div class="fitem">
								<label>
									合同名称:
								</label>
								<select id="cc" name="contractinfo_id" style="width:250px;">
								</select>
								<input id="cc_field" name="contractinfo_name" type="hidden">
							</div>
						</td>
						

					</tr>
				</table>
			</div>
			<!-- 项目信息展示区域 -->
		  
		  <br/>
			
			<div>
				<table  style="border:1px solid #b3dfda;width: 700px" >

					<tr>
					
						<td width="30%">

							<div class="fitem">
								<label>
									所属公司:
								</label>
								  <select id="company_code" class="easyui-combotree"
								name="company_code" style="width: 120px;"></select>
							</div>

						</td>
						
						
						<td width="30%">
							<div class="fitem">
								<label>
							 		项目名称:
								</label>
								<input name="id" size="10" type="hidden" >
								<input name="projectName" style="width: 120px;" required="true" class="easyui-validatebox" >
							</div>
						</td>
						
						
						<td>
							<div class="fitem">
								<label>
									物管信息:
								</label>
								<input name="managerCompanyInfo" class="easyui-validatebox" validType="number" style="width: 120px;">
							</div>
						</td>
						
						
					</tr>
					
					
					<tr>
					
					<td width="40%">
							<div class="fitem">
								<label>
									施工单位:
								</label>
								<input name="constructionOrganization"  style="width: 120px;"  class="easyui-validatebox" >
							</div>
						</td>
						
					  <td width="30%">
							<div class="fitem">
								<label>
									施工地点:
								</label>
								<input name="constructionAddr"  style="width: 120px;"  class="easyui-validatebox" >
							</div>
						</td>
						
					
						<td>
							<div class="fitem">
								<label>
									管道长度:
								</label>
								<input name="pipeLength" class="easyui-validatebox" validType="number" style="width: 120px;" >m
							</div>
						</td>
									
					</tr>
						
					<tr>
						<td>
							<div class="fitem">
								<label>
									总户数&nbsp;&nbsp;&nbsp;:
								</label>
								<input name="residentCount" style="width: 120px;"  validType="number">户
							</div>
						</td>
						<td>
							<div class="fitem">
								<label>
									总面积&nbsp;&nbsp;&nbsp;:
								</label>
								<input name="buildArea" class="easyui-validatebox"  style="width: 120px;"  validType="number">m2
							</div>
						</td>
						
						<td>
							<div class="fitem">
								<label>
									化粪池数:
								</label>
								<input name="pitCount" class="easyui-validatebox" validType="number" style="width: 120px;" >个
							</div>
						</td>		
						
					</tr>
					
					<tr>
						<td colspan="3">
						
							<div class="fitem">
								<label>
									项目说明:
								</label>
								<textarea rows="2" cols="40" name="projectSpec" ></textarea>
							</div>
					
						
						</td>
					</tr>
					
					

				</table>
				
				<div align="center">
					<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
					onclick="project_save()">保存</a>
				</div>
				
				
			
			</div>	
			
			</form>
			
		
		</div>


  
	
		
		
	</div>
    
		
	
				
					
</div>
		
	
</body>
</html>